<?php

/**
 * This is the model class for table "{{users}}".
 *
 * The followings are the available columns in table '{{users}}':
 * @property integer $id
 * @property string $name
 * @property string $email
 * @property string $password
 * @property string $nick
 * @property string $gender
 * @property string $avatar
 * @property string $birth
 * @property string $website
 * @property string $mobile
 * @property string $url_token
 * @property string $last_login
 * @property string $create_time
 * @property string $update_time
 * @property string $status
 * @property string $province
 * @property string $city
 * @property string $brief
 */
class User extends CActiveRecord
{
    public $verifyCode;

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return User the static model class
     */
    public static function model($className = __CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        // 如果设置了tablePrefix,那么这里可以这样定义表名
        return '{{users}}';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('name, password, birth, last_login, email', 'required'),
            array('name, email, password, avatar, website', 'length', 'max' => 50),
            array('nick, mobile, url_token', 'length', 'max' => 20),
            array('gender', 'length', 'max' => 6),
            array('status', 'length', 'max' => 8),
            array('province, city', 'length', 'max' => 10),
            array('brief', 'length', 'max' => 140),
            array('create_time, update_time', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, name, email, password, nick, gender, avatar, birth, website, mobile, url_token, last_login, create_time, update_time, status, province, city, brief', 'safe', 'on' => 'search'),

            // 我加的,用以支持验证码
            //array('verifyCode', 'captcha', 'on'=>'insert', 'allowEmpty'=> !extension_loaded('gd')),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'name' => '用户名',
            'email' => '邮箱',
            'password' => '密码',
            'nick' => '昵称',
            'gender' => '性别',
            'avatar' => '头像',
            'birth' => '出生年月',
            'website' => '个人网站',
            'mobile' => '手机',
            'url_token' => '个性网址',
            'last_login' => '上次登录时间',
            'create_time' => '创建时间',
            'update_time' => '更新时间',
            'status' => '状态',
            'province' => '省份',
            'city' => '城市',
            'brief' => '个人简介',
            'captcha' => '验证码',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id);
        $criteria->compare('name', $this->name, true);
        $criteria->compare('email', $this->email, true);
        $criteria->compare('password', $this->password, true);
        $criteria->compare('nick', $this->nick, true);
        $criteria->compare('gender', $this->gender, true);
        $criteria->compare('avatar', $this->avatar, true);
        $criteria->compare('birth', $this->birth, true);
        $criteria->compare('website', $this->website, true);
        $criteria->compare('mobile', $this->mobile, true);
        $criteria->compare('url_token', $this->url_token, true);
        $criteria->compare('last_login', $this->last_login, true);
        $criteria->compare('create_time', $this->create_time, true);
        $criteria->compare('update_time', $this->update_time, true);
        $criteria->compare('status', $this->status, true);
        $criteria->compare('province', $this->province, true);
        $criteria->compare('city', $this->city, true);
        $criteria->compare('brief', $this->brief, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }
}